package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;
    /**
     * 查看购物车
     * @return
     */
    @RequestMapping("cart.html")
    public String index(){
        return "cart/index";
    }

    /**
     * 添加购物车
     * @param request
     * @return
     */
    @RequestMapping("addCart.html")
    public String addCart(HttpServletRequest request) {
        String skuId = request.getParameter("skuId");
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.valueOf(skuId));
        request.setAttribute("skuInfo", skuInfo);
        request.setAttribute("skuNum",request.getParameter("skuNum"));
        return "cart/addCart";
    }
}
